package com.fc.push.logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.fc.remoting.core.HttpProtocolTask;
import com.fc.remoting.handler.HttpRequestHandler;
@Component
@Aspect
public class LogSystemAop {
	
	Logger log = LoggerFactory.getLogger(HttpProtocolTask.class);
	
	static ThreadLocal<Long> previousMethodTime = new ThreadLocal<Long>();
    public LogSystemAop(){
    }
    
    @Pointcut("execution(* com.fc.persistence.core.TranscationImpl.*(..))")
    private void dboperation(){}
    
    @Pointcut("execution(* com.fc.push.handler.pub.service.RedisServiceUtil.*(..))")
    private void redisoperation(){}
    
    @Pointcut("execution(*  com.fc.push.handler.pub.service.MqttPublishUtil.*(..))")
    private void mqttoperation(){}
    
    @Pointcut("execution(* com.fc.push.handler.pub.service.APNsPublishUtil.*(..))")
    private void apnoperation(){}
    
    @Pointcut("execution(* com.fc.push.handler.pub.service.WebPublishService.*(..))")
    private void webserviceoperation(){}
    
    
    @Pointcut("execution(* com.fc.push.handler.pub.service.GlobalService.*(..))")
    private void globaloperation(){}
    
    
    
    @Before("dboperation()||redisoperation()||mqttoperation()||apnoperation()||webserviceoperation()||globaloperation()")
    public void beforeMethod(JoinPoint joinPoint){
    	Signature signature = joinPoint.getSignature();
    	previousMethodTime.set(System.currentTimeMillis());
    	log.info(signature.getDeclaringTypeName()+"."+signature.getName() + ":开始执行" );
    }
    
    @AfterReturning("dboperation()||redisoperation()|| mqttoperation()||apnoperation()||webserviceoperation()||globaloperation()")
    public void afterMethod(JoinPoint joinPoint){
    	Signature signature = joinPoint.getSignature();
    	long time = (System.currentTimeMillis()-previousMethodTime.get());
    	
    	log.info(signature.getDeclaringTypeName()+"."+signature.getName() + ":结束执行，耗时" + time +"豪秒" );
    }
}
